﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Oracle.DataAccess.Client;

namespace Testify
{
    public partial class Users : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                // code for subsequent refreshes
            }
            else
            {
                // code for first load
            }

            // code for every page load
        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {
            try
            {
                dsUsers.Insert();
            }
            catch (System.Data.OracleClient.OracleException oe)
            {
                lblError.Text    = "User Names must be unique.";
                lblError.Visible = true;
            }

            // Clear the fields for another Add
            ddlUserType.SelectedValue = String.Empty;
            txtUserName.Text = String.Empty;
            txtPassWord.Text = String.Empty;
            txtFirstName.Text = String.Empty;
            txtLastName.Text = String.Empty;
        }

        protected void grdUsers_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drvUser = (DataRowView)e.Row.DataItem;

                if (drvUser["user_maint"].ToString() == "D")
                    e.Row.BackColor = System.Drawing.Color.Gray;
            }
        }

        protected void grdUsers_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
            e.ExceptionHandled = true;

            if (e.Exception != null)
            {
                e.KeepInEditMode = true;

                lblError.Text = "User Names must be unique.";
                lblError.Visible = true;
            }
        }
    }
}